/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package BLL;

import DAL.ConnectUnit;
import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.JComboBox;
import javax.swing.JOptionPane;
import org.jdesktop.swingx.JXDatePicker;

/**
 *
 * @author Nguyen Phi Hung
 */
public class Unity {
    ConnectUnit conn;
    SimpleDateFormat formater = new SimpleDateFormat("dd/MM/yyyy");
    public Unity(){
        conn = DAL.DAL.getDAL();
    }
    
    public void load_combobox(JComboBox cb,String table,String column) throws Exception
    {
        ResultSet rss=conn.Select(table);
        while(rss.next())
        {
            String k=rss.getString(column);
            cb.addItem(k);
        }
    }  
    public java.sql.Date ConvertDate(JXDatePicker jXDatePicker1)
    {
        try {
            String str=formater.format(jXDatePicker1.getDate()).toString();
            String[] arr=str.split("/");
            
            java.sql.Date date=new java.sql.Date(Integer.parseInt(arr[2])-1900, Integer.parseInt(arr[1])-1, Integer.parseInt(arr[0]));
            //JOptionPane.showMessageDialog(null, date);
            return date;
        } catch (Exception e) {
        }
        return null;
    }

    public String toString(JXDatePicker jXdatepicker) {
        String s;
        s = formater.format(jXdatepicker.getDate()).toString();
        return s.trim();
    }

}
